package Q338

/**
 * 比特位计数
 * @author 23737
 * @date 2022.5.9
 */
class Main {

}

fun main() {
    val a = 5
    for (countBit in Solution().countBits(a)) {
        println(countBit)
    }
}

class Solution {
    fun countBits(n: Int): IntArray {
        if (n == 0) return intArrayOf(0)
        var res = IntArray(n + 1)
        for(i in 0 .. n){
            res[i] = Integer.bitCount(i)
        }
        return res
    }
}